<template>
  <div class="icons">
    <swiper :options="swiperOption" v-if="iconsLength">
      <swiper-slide v-for="(page,index) in pages" :key="index">
        <div class="icon" v-for="item in page" :key="item.id">
          <div class="icon-img">
            <img class="icon-img-con" :src="item.imgUrl" alt="">
          </div>
          <p class="icon-desc">{{item.desc}}</p>
        </div>
      </swiper-slide>
      <div v-if="listSpot" class="swiper-pagination"  slot="pagination"></div>
    </swiper>
  </div>
</template>
<script type="text/ecmascript-6">
export default{
  name: 'HomeIcons',
  props: {
    List: Array
  },
  data () {
    return {
      swiperOption: {
        pagination: '.swiper-pagination',
        autoplay: false
      },
      listSpot: false
    }
  },
  computed: {
    iconsLength () {
      return this.List.length
    },
    pages () {
      const _this = this
      const pages = []
      this.List.forEach((item, index) => {
        const page = Math.floor(index / 8)
        if (!pages[page]) {
          pages[page] = []
        }
        pages[page].push(item)
      })
      if (pages.length > 1) {
        _this.listSpot = true
      }
      return pages
    }
  }
}
</script>
<style lang="stylus" scoped>
  @import "~styles/varibles.styl";
  @import "~styles/mixins.styl";
  .icons >>> .swiper-pagination-bullets
    bottom: 0px!important
  .icons >>> .swiper-pagination-bullet-active
    background: rgba(0,175,190,.8)
  .icons >>> .swiper-container
    height: 0
    padding-bottom: 54%
  .icons
    padding-bottom: 10px
    padding-top: .15rem
  .icon
    overflow: hidden
    float: left
    width: 25%
    height: 0
    padding-bottom: 25%
    .icon-img
      box-sizing: border-box
      padding: 0.15rem
      width: 70%
      margin: 0 auto;
      .icon-img-con
        width: 100%
        height: 100%
        display: block
    .icon-desc
      text-align: center
      height: .44rem
      line-height: .44rem
      color: $darkTextColor
      ellipsis()
</style>
